﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _04组合模式
{
    public class Dept : Component
    {
        /// <summary>
        /// 部门类，相当于树枝
        /// </summary>
        /// <param name="name"></param>
        public Dept (string name) : base(name)
        {
            this._name = name;
        }
        public List<Component> children = new List<Component>();
        //添加子节点
        public override void Add(Component c)
        {
            children.Add(c);
        }
        //删除子节点
        public override void Remove(Component c)
        {
            children.Remove(c);
        }
        //展示自己和和内部的所有子节点，这里是组合模式的核心
        public override void DisPlay(int dept)
        {
            Console.WriteLine(new string('-',dept)+_name);
            {
                foreach (var item in children )
                {
                    //这里用到了递归的思想
                    item.DisPlay(dept + 4);
                }
            }
        }
    }
}
